<%@page import="java.util.ArrayList"%>
<%@page import="telefonia.entity.Pais"%>
<%@page import="telefonia.dao.DaoPais"%>
<%@page import="telefonia.dao.DaoRegion"%>
<%@page import="telefonia.entity.Region"%>
<!-- Rescate de variables formulario -->

<%
    String id = "";
    String descripcion = "";
    String idPais = "";

    ArrayList<Region> regiones = new ArrayList<Region>();

    if (request.getParameter("txtId") != null) {
        id = request.getParameter("txtId");
        descripcion = request.getParameter("txtDescripcion");
        idPais = request.getParameter("cboPais");
    }

%>

<!--Controlador
<%
    if (request.getParameter("btnLeer") != null) {

        regiones.add(DaoRegion.sqlRead(new Region(Integer.parseInt(id))));
    }
    if (request.getParameter("btnGuardar") != null) {
        DaoRegion.sqlInsert(new Region(Integer.parseInt(id),descripcion,new Pais(idPais)));
    }
    if (request.getParameter("btnActualizar") != null) {
    }
    if (request.getParameter("btnEliminar") != null) {
        DaoRegion.sqlDelete(new Region(Integer.parseInt(id)));
    }
    if (request.getParameter("btnCancelar") != null) {
    }

%>
-->

<%-- 
    Document   : FrPais
    Created on : 07-10-2013, 10:19:17 AM
    Author     : Duoc
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Region</title>
    </head>
    <body>
        <form method="GET">
            <table border="0">
                <thead>
                    <tr>
                        <th colspan="4">Gestion Regiones</th>

                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>Id</td>
                        <td><input type="text" name="txtId" id="txtId" value="<% out.write(id);%>" size="10" /></td>
                        <td><input type="submit" id="btnBus" name="btnBus" value="?"/></td>
                        <td><input type="submit" name="btnLeer" id="btnLeer" value="Leer"/></td>
                        <td><input type="submit" value="btnSalir" value="Salir" /></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>Descripcion</td>
                        <td><input type="text" name="txtDescripcion" value="<% out.write(descripcion);%>" /></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>Pais</td>
                        <td><select id="cboPais" name="cboPais">
                                <option value="0">Seleccionar</option>
                        </select>
                        </td>
                    </tr>
                    <tr>
                        <td><input type="submit" value="Guardar" name="btnGuardar" id="btnGuardar"/></td>
                        <td><input type="submit" value="Eliminar" name="btnEliminar" id="btnEliminar"/></td>
                        <td><input type="submit" value="Actualizar" name="btnActualizar" id="btnActualizar"/></td>
                        <td></td>
                    </tr>

                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                </tbody>
            </table>

            <table>
                <tr>
                    <th>ID</th>
                    <th>Descripcion</th>
                </tr>
                <%
                    if (regiones.size() > 0) {


                        for (Region region : regiones) {

                            out.write("<tr>");
                            out.write("<td>");
                            out.write(region.getIdRegion());
                            out.write("</td>");
                            out.write("<td>");
                            out.write(region.getDescripcion());
                            out.write("</td>");
                            out.write("</tr>");
                        }

                    }

                %>


            </table>
        </form>
    </body>
</html>